<?php

Raise::load('db.core.RaiseDbRelationship');
Raise::load('core.RaiseCollection');

/**
 * RaiseDbBelongsToOne class
 * Defines that this model belongs to one of the other model
 * A -> B; A has a field that references B, then it is said that table A belong to table B
 *
 * @author Sam Yong
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.db.relationship
 * @since 1.2
 */
class RaiseDbBelongsToOne extends RaiseDbRelationship {
    
    /**
     * The model that this model belongs to
     * @var string|RaiseDbModel
     */
    private $model;
    
    /**
     * The foreign key that identifies the target model
     * @var RaiseCollection|string
     */
    private $foreignKey;
    
    /**
     * Create a new RaiseDbBelongsToOne relationship
     * @param string|RaiseDbModel $model
     * @param RaiseCollection|string $foreignKey 
     */
    public function __construct($model, $foreignKey = null){
        $this->model($model);
        $this->foreignKey($foreignKey);
    }
    
    /**
     * Get or set the model that this model belongs to
     * @param string|RaiseDbModel $m (optional) Set the new model that this model belongs to
     * @return string|RaiseDbModel
     */
    public function model($m = null){
        if(func_num_args() == 1){
            $this->model = $m;
        }
        return $this->model;
    }

    /**
     * Get or set foreign key that identifies the target model
     * @param RaiseCollection|string $f (optional) Set the foreign key that identifies the target model
     * @return RaiseCollection|string
     */
    public function foreignKey($f = null){
        if(func_num_args() == 1){
            $this->foreignKey = $f;
        }
        return $this->foreignKey;
    }
    
}
